function Stack() {
  this.item = [];
  let p = Stack.prototype;
  p.push = function(ele) {
    this.item.push(ele);
  };
  p.pop = function() {
    return this.item.pop();
  };
  p.peek = function() {
    return this.item[this.item.length - 1];
  };
  p.isEmpty = function() {
    if (this.item.length === 0) return true;
    else return false;
  };
  p.toString = function() {
    return this.item.join(" ");
  };
}

let s = new Stack();
s.push(10);
s.push(20);
s.push(30);
s.push(40);
s.push(50);
s.push(60);
s.push(70);
s.push(80);
console.log(s.toString());
s.pop();
console.log(s.toString());
s.peek();
s.isEmpty();
s.toString();
/**
 * 十进制转二进制
 */
function dec2bin(ten) {
  let stack = new Stack();
  let remainder;
  while (ten > 0) {
    remainder = ten % 2;
    ten = Math.floor(ten / 2);
    stack.push(remainder);
  }
  let str = "";
  while (!stack.isEmpty()) {
    str += stack.pop();
  }
  return str;
}
console.log(dec2bin(11));
/**
 * 二进制转十进制
 */
function bin2dec(two) {
  let items = two.split("");
  let i = 0;
  let sum = 0;
  while (items.length > 0) {
    sum += items.pop() * Math.pow(2, i);
    i++;
  }
  return sum;
}
console.log(bin2dec("1011"));
